angular.module('Controller')
.controller('WFBasicParamsEditCtrl', ($scope,NgTableParams,commonUtil,wfAlert,commonConstant,$http, $uibModalInstance, items) ->
    type=items.type
    $scope.data=items.data
    $scope.modalTitle=if type=='new' then '新建参数' else '编辑参数'
#    if type=='edit'
#        $scope.enabled=if  $scope.enabled==true then 1 else 0
    $scope.modalEnableList=commonConstant.enabledList()
    $scope.newData=()->
        postData={
            accountId:2
            key:$scope.data.key
            name:$scope.data.name
            catelogId:null
            enabled: $scope.data.enabled
            remark:$scope.data.remark
        }
        getParams=commonUtil.transferGetParam(postData)
        $http.post('/dictionary/index',postData)
        .success((resp)->
            if(resp.code==0)
                if resp.code==0
                    wfAlert.toastInfo('字典索引创建成功')
                    $uibModalInstance.close('done')
                else
                    wfAlert.toastError('字典索引创建失败：',resp.message)
            else
                wfAlert.toastError('新建参数失败：',resp.message)
        )
    $scope.editData=()->
        putData={
            key:$scope.data.key
            name:$scope.data.name
            catelogId:null
            enabled: $scope.data.enabled
            remark:$scope.data.remark
        }
        getParams=commonUtil.transferGetParam(putData)
        $http.put('/dictionary/index/'+$scope.data.id,putData)
        .success((resp)->
            if(resp.code==0)
                wfAlert.toastInfo('修改参数成功')
                $uibModalInstance.close('done')
            else
                wfAlert.toastError('修改参数失败：',resp.message)

        )
    $scope.judge=()->
        if type=='new'
            false
        else
            true
    $scope.confirm = ()->
        if type=='new'
            $scope.newData()
        else
           $scope.editData()
    $scope.cancel =()->
        $uibModalInstance.dismiss('cancel')

)